package com.neusoft.elmboot.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.neusoft.elmboot.po.Orders;
import com.neusoft.elmboot.service.OrdersService;
import com.neusoft.elmboot.util.APIResponse;

@RestController
@RequestMapping("/Orders")
public class OrdersController {
	@Autowired
	private OrdersService ordersService;

	@PostMapping
	public APIResponse createOrders(Orders orders) throws Exception {
		return APIResponse.success(ordersService.createOrders(orders));
	}

	@GetMapping("/getOrdersById")
	public APIResponse getOrdersById(Orders orders) throws Exception {
		return APIResponse.success(ordersService.getOrdersById(orders.getOrderId()));
	}

	@GetMapping("/list")
	public APIResponse listOrdersByUserId(Orders orders) throws Exception {
		return APIResponse.success(ordersService.listOrdersByUserId(orders.getUserId()));
	}

	@PutMapping
	public APIResponse pay(Integer orderId){
		return APIResponse.success(ordersService.pay(orderId));
	}

}